/*     */ package com.qmsk.business.store.vicecard.controller;
/*     */ 
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.member.memberDepositConsumeRecord.dao.MemberDepositConsumeRecordDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.business.store.vicecard.dao.ViceCardDao;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.gson.out.GsonEbRstData;
/*     */ import com.utils.http.HttpGsonPtResponseUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.IOException;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"viceCard"})
/*     */ public class ViceCardController
/*     */ {
/*  40 */   private static final Logger logger = Logger.getLogger(ViceCardController.class);
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private ViceCardDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositConsumeRecordDAO memberDepositConsumeRecordDAO;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfMemberId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try {
/*  58 */       Map params = new HashMap();
/*  59 */       MapUtils.addToMap(params, "id", id);
/*  60 */       if (!(ShopMap.getShareMemberOfShopId(shopId).booleanValue())) {
/*  61 */         MapUtils.addToMap(params, "shopId", shopId);
/*     */       }
/*  63 */       GsonEbRst gsonEbRst = this.dao.getViceCardOpt(params, 0, (short) 1);
/*  64 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  66 */       logger.error(e);
/*  67 */       ResponseUtils.setErrorMsgResponse(
/*  68 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/memberId/{memberID}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getOptOfMemberId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("memberID") Long memberId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  87 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  89 */       Map params = new HashMap();
/*  90 */       MapUtils.addToMap(params, "memberId", memberId);
/*  91 */       GsonEbRst gsonEbRst = this.dao.getViceCardOpt(params, nPageIdx.intValue(), 
/*  92 */         nPageSize.shortValue());
/*  93 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  95 */       logger.error(e);
/*  96 */       ResponseUtils.setErrorMsgResponse(
/*  97 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getOptOfShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 115 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 117 */       Map params = new HashMap();
/* 118 */       MapUtils.addToMap(params, "status", 
/* 119 */         RequestUtils.getInt(request, "status"));
/*     */ 
/* 121 */       MapUtils.addToMap(params, "vcardNo", 
/* 122 */         RequestUtils.getString(request, "CardNo"));
/* 123 */       GsonEbRst gsonEbRst = this.dao.getViceCardOpt(params, nPageIdx.intValue(), 
/* 124 */         nPageSize.shortValue());
/* 125 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 127 */       logger.error(e);
/* 128 */       ResponseUtils.setErrorMsgResponse(
/* 129 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/cardNo/{cardNo}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfCardNo(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("cardNo") String cardNo)
/*     */   {
/*     */     try
/*     */     {
/* 138 */       Map params = new HashMap();
/* 139 */       MapUtils.addToMap(params, "cardNo", cardNo);
/* 140 */       if (ShopMap.getShareMemberOfShopId(shopId).booleanValue())
/* 141 */         MapUtils.addToMap(params, "groupId", 
/* 142 */           ShopMap.getGroupIdOfShopId(shopId));
/*     */       else {
/* 144 */         MapUtils.addToMap(params, "shopId", shopId);
/*     */       }
/* 146 */       GsonEbRst gsonEbRst = this.dao.getViceCardOpt(params, 0, (short) 1);
/* 147 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 149 */       logger.error(e);
/* 150 */       ResponseUtils.setErrorMsgResponse(
/* 151 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/vcardNo/{vcardNo}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfVCardNo(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("vcardNo") String vcardNo)
/*     */   {
/*     */     try
/*     */     {
/* 160 */       Map params = new HashMap();
/* 161 */       MapUtils.addToMap(params, "vcardNo", vcardNo);
/* 162 */       if (ShopMap.getShareMemberOfShopId(shopId).booleanValue())
/* 163 */         MapUtils.addToMap(params, "groupId", 
/* 164 */           ShopMap.getGroupIdOfShopId(shopId));
/*     */       else {
/* 166 */         MapUtils.addToMap(params, "shopId", shopId);
/*     */       }
/* 168 */       GsonEbRst rst = this.dao.getViceCardOpt(params, 0, (short) 1);
/* 169 */       if (rst.getResult().isExistsData())
/*     */       {
/* 172 */         Date uneftDate = (Date)rst.getResult().getValueOfIdx(0, 
/* 173 */           "uneftDate");
/* 174 */         if ((uneftDate != null) && 
/* 177 */           (uneftDate.before(new Date()))) {
/* 178 */           ResponseUtils.setErrorMsgResponse("卡已失效", response);
/* 179 */           return;
/*     */         }
/*     */       }
/*     */       else {
/* 183 */         ResponseUtils.setErrorMsgResponse("卡不存在", response);
/* 184 */         return;
/*     */       }
/* 186 */       ResponseUtils.setResponseResult(rst, response);
/*     */     } catch (SQLException e) {
/* 188 */       logger.error(e);
/* 189 */       ResponseUtils.setErrorMsgResponse(
/* 190 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */     throws IOException
/*     */   {
/*     */     try
/*     */     {
/* 210 */       int nResult = 0;
/* 211 */       String sData = RequestUtils.getStringOfData(request);
/* 212 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 213 */       nResult = this.dao.applyUpdates(p);
/* 214 */       if ((nResult > 0) && (p.isExistsInsertRows())) {
/* 215 */         for (int i = 0; i < p.getListInsertRows().size(); ++i) {
/* 216 */           GsonHeadOneRow r = (GsonHeadOneRow)p.getListInsertRows().get(i);
/* 217 */           Long memberId = ObjectComm.objectToLong(r
/* 218 */             .getValueOfName("memberID"));
/* 219 */           r.autoAddHeadData("memberID", 
/* 220 */             this.memberDao.getOutMIdOfId(memberId));
/*     */         }
/* 222 */         nResult = toPt(p.objectToJsonStr(), 
/* 223 */           ShopMap.getOutIdOfShopId(shopId), response, "insert").intValue();
/*     */       }
/*     */ 
/* 225 */       if (nResult > 0)
/* 226 */         DbConnection.commit();
/*     */       else {
/* 228 */         DbConnection.rollback();
/*     */       }
/* 230 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 231 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 232 */         response);
/*     */     } catch (Exception e) {
/* 234 */       DbConnection.rollback();
/* 235 */       logger.error(e);
/* 236 */       ResponseUtils.setErrorMsgResponse(
/* 237 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 238 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */     throws IOException
/*     */   {
/*     */     try
/*     */     {
/* 257 */       int nResult = 0;
/* 258 */       String sData = RequestUtils.getStringOfData(request);
/* 259 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 260 */       if ((p != null) && 
/* 261 */         (p.isExistsUpdateRows())) {
/* 262 */         Long memberId = null;
/* 263 */         Double deposit = Double.valueOf(0.0D);
/* 264 */         for (int i = p.getListUpdateRows().size() - 1; i >= 0; --i) {
/* 265 */           GsonHeadOneRow r = (GsonHeadOneRow)p.getListUpdateRows().get(i);
/* 266 */           Integer selted = ObjectComm.objectToInteger(r
/* 267 */             .getValueOfName("selted"));
/* 268 */           if ((selted != null) && (selted.intValue() == 0)) {
/* 269 */             p.getListUpdateRows().remove(i);
/*     */           } else {
/* 271 */             Double ndeposit = ObjectComm.objectToDouble(
/* 272 */               r.getValueOfName("totlAmt"), Integer.valueOf(0));
/* 273 */             memberId = ObjectComm.objectToLong(
/* 274 */               r.getValueOfName("memberId"), Integer.valueOf(0));
/* 275 */             deposit = Double.valueOf(deposit.doubleValue() + ndeposit.doubleValue());
/* 276 */             r.autoInsertHeadData("dodate", new Date());
/* 277 */             r.autoInsertHeadData("amt", ndeposit);
/*     */           }
/*     */         }
/* 280 */         Double totalAmt = this.dao.getTotalAmtOfMemberID(memberId, 
/* 281 */           shopId);
/* 282 */         deposit = Double.valueOf(deposit.doubleValue() + totalAmt.doubleValue());
/* 283 */         if (memberId != null) {
/* 284 */           Double nDeposit = this.shopMemberDAO.getShopMemberDeposit(
/* 285 */             shopId, memberId);
/* 286 */           if ((nDeposit.doubleValue() > 0.0D) && (nDeposit.doubleValue() < deposit.doubleValue())) {
/* 287 */             ResponseUtils.setErrorMsgResponse("用户预存金额不足", 
/* 288 */               response);
/* 289 */             return;
/*     */           }
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 295 */       p.delHead("selted");
/* 296 */       nResult = this.dao.applyUpdates(p);
/* 297 */       if ((nResult > 0) && (p.isExistsUpdateRows())) {
/* 298 */         for (int i = 0; i < p.getListUpdateRows().size(); ++i) {
/* 299 */           GsonHeadOneRow r = (GsonHeadOneRow)p.getListUpdateRows().get(i);
/* 300 */           Long memberId = ObjectComm.objectToLong(r
/* 301 */             .getValueOfName("memberID"));
/* 302 */           r.autoAddHeadData("memberID", 
/* 303 */             this.memberDao.getOutMIdOfId(memberId));
/*     */         }
/* 305 */         nResult = toPt(p.objectToJsonStr(), 
/* 306 */           ShopMap.getOutIdOfShopId(shopId), response, "edit").intValue();
/*     */       }
/*     */ 
/* 308 */       if (nResult > 0)
/* 309 */         DbConnection.commit();
/*     */       else {
/* 311 */         DbConnection.rollback();
/*     */       }
/* 313 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 314 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 315 */         response);
/*     */     } catch (Exception e) {
/* 317 */       DbConnection.rollback();
/* 318 */       logger.error(e);
/* 319 */       ResponseUtils.setErrorMsgResponse(
/* 320 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 321 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 335 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 337 */       String[] strParams = id.split(",");
/* 338 */       int nResult = this.dao.deleteParams(strParams);
/* 339 */       nResult = toPtDel(id, ShopMap.getOutIdOfShopId(shopId), response).intValue();
/* 340 */       DbConnection.commit();
/* 341 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 342 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 343 */         response);
/*     */     } catch (Exception e) {
/* 345 */       DbConnection.rollback();
/* 346 */       logger.error(e);
/* 347 */       ResponseUtils.setErrorMsgResponse(
/* 348 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 349 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */     throws SQLException
/*     */   {
/* 367 */     Long id = RequestUtils.getLong(request, "id");
/* 368 */     Long memberId = RequestUtils.getLong(request, "memberId");
/* 369 */     int nResult = 0;
/*     */     try {
/* 371 */       if ((id != null) && (id.longValue() > 0L)) {
/* 372 */         Double totalAmt = this.dao.getTotalAmtOfid(id);
/* 373 */         Double deposit = this.shopMemberDAO.getShopMemberDeposit(shopId, 
/* 374 */           memberId);
/* 375 */         if ((deposit.doubleValue() > 0.0D) && (deposit.doubleValue() >= totalAmt.doubleValue())) {
/* 376 */           deposit = Double.valueOf(deposit.doubleValue() - totalAmt.doubleValue());
/* 377 */           Map params = new HashMap();
/* 378 */           MapUtils.addToMap(params, "memberId", memberId);
/* 379 */           MapUtils.addToMap(params, "shopId", shopId);
/* 380 */           MapUtils.addToMap(params, "amount", deposit);
/* 381 */           nResult = this.shopMemberDAO.update_DopositAmountInc(params);
/* 382 */           params.remove("shopId");
/* 383 */           nResult = this.memberDao.update_DopositAmountInc(params);
/*     */         } else {
/* 385 */           ResponseUtils.setErrorMsgResponse("预存不足", response);
/* 386 */           return;
/*     */         }
/* 388 */         if (nResult > 0) {
/* 389 */           String[] heads = { "MemberID", "ShopID", 
/* 390 */             "Date", "ConsumeAmout" };
/* 391 */           Object[] datas = { memberId, shopId, 
/* 392 */             new Date(), deposit };
/* 393 */           GsonHeadOneRow g = new GsonHeadOneRow(heads, datas);
/* 394 */           nResult = this.memberDepositConsumeRecordDAO
/* 395 */             .insertGsonHeadOneRow(g);
/*     */         }
/* 397 */         Long outMId = this.memberDao.getOutMIdOfId(memberId);
/* 398 */         if ((outMId != null) && (outMId.longValue() > 0L) && (nResult > 0)) {
/* 399 */           nResult = toPtCheck(String.valueOf(id), 
/* 400 */             ShopMap.getOutIdOfShopId(shopId), outMId, 
/* 401 */             deposit, response).intValue();
/*     */         }
/*     */ 
/* 403 */         if (nResult > 0) {
/* 404 */           nResult = this.dao.updateCheckOfId(id);
/*     */         }
/*     */       }
/*     */ 
/* 408 */       if (nResult > 0)
/* 409 */         DbConnection.commit();
/*     */       else {
/* 411 */         DbConnection.rollback();
/*     */       }
/* 413 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 414 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 415 */         response);
/*     */     } catch (Exception e) {
/* 417 */       DbConnection.rollback();
/* 418 */       logger.error(e);
/* 419 */       ResponseUtils.setErrorMsgResponse(
/* 420 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 421 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private Integer toPt(String sGsonInData, Long shopId, HttpServletResponse response, String method) throws Exception
/*     */   {
/* 427 */     String sData = "data=" + sGsonInData + "&shopId=" + 
/* 428 */       shopId;
/* 429 */     String url = "ptViceCard/" + method;
/* 430 */     GsonEbRst rst = 
/* 431 */       HttpGsonPtResponseUtils.getPtEbRst(url, sData, response);
/* 432 */     if ((rst != null) && (rst.getState() == 0)) {
/* 433 */       return Integer.valueOf(1);
/*     */     }
/* 435 */     return null;
/*     */   }
/*     */ 
/*     */   private Integer toPtDel(String id, Long shopId, HttpServletResponse response)
/*     */     throws Exception
/*     */   {
/* 441 */     String sData = "id=" + id + "&shopId=" + shopId;
/* 442 */     String url = "ptViceCard/del";
/* 443 */     GsonEbRst rst = 
/* 444 */       HttpGsonPtResponseUtils.getPtEbRst(url, sData, response);
/* 445 */     if ((rst != null) && (rst.getState() == 0)) {
/* 446 */       return Integer.valueOf(1);
/*     */     }
/* 448 */     return null;
/*     */   }
/*     */ 
/*     */   private Integer toPtCheck(String id, Long shopId, Long memberId, Double deposit, HttpServletResponse response)
/*     */     throws Exception
/*     */   {
/* 455 */     String sData = "id=" + id + "&shopId=" + shopId + 
/* 456 */       "&memberId=" + memberId + "&deposit=" + 
/* 457 */       deposit;
/* 458 */     String url = "ptViceCard/check";
/* 459 */     GsonEbRst rst = 
/* 460 */       HttpGsonPtResponseUtils.getPtEbRst(url, sData, response);
/* 461 */     if ((rst != null) && (rst.getState() == 0)) {
/* 462 */       return Integer.valueOf(1);
/*     */     }
/* 464 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.vicecard.controller.ViceCardController
 * JD-Core Version:    0.5.3
 */